package be.bejug.scrumadmin;

import be.bejug.scrumadmin.components.Header;
import be.bejug.scrumadmin.components.panels.ContentPanel;
import be.bejug.scrumadmin.enums.Size;
import be.bejug.scrumadmin.enums.Style;

import com.vaadin.terminal.gwt.client.ui.AlignmentInfo.Bits;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.VerticalLayout;

/**
 * 
 * @author Glenn Dejaeger
 * 
 */
public class MainView extends VerticalLayout {

	private static final long serialVersionUID = -8421758733452231380L;

	private ContentPanel contentPanel;

	private Header header;

	public MainView(final ContentPanel contentPanel) {
		this.contentPanel = contentPanel;
		setSizeFull();
		init();
	}

	protected void init() {
		VerticalLayout vLayout = new VerticalLayout();
		vLayout.setWidth(Size.HEADER_WIDTH.getValue(),
				Size.HEADER_WIDTH.getUnits());
		vLayout.setHeight(Size.APP_HEIGHT.getValue(),
				Size.APP_HEIGHT.getUnits());
		header = new Header();

		VerticalLayout contentLayout = new VerticalLayout();
		contentLayout.setSizeFull();

		VerticalLayout contentTopLayout = new VerticalLayout();
		contentTopLayout.setStyleName(Style.CONTENT_TOP.getStyleName());
		contentTopLayout.setWidth(Size.HEADER_WIDTH.getValue(),
				Size.HEADER_WIDTH.getUnits());
		contentTopLayout.setHeight(Size.CONTENT_TOP_HEIGHT.getValue(),
				Size.CONTENT_TOP_HEIGHT.getUnits());

		VerticalLayout contentCenterLayout = new VerticalLayout();
		contentCenterLayout.setSizeFull();
		contentCenterLayout.setStyleName(Style.CONTENT_CENTER.getStyleName());
		if (contentPanel != null) {
			contentCenterLayout.addComponent(contentPanel);
			contentCenterLayout.setComponentAlignment(contentPanel,
					Bits.ALIGNMENT_HORIZONTAL_CENTER,
					Bits.ALIGNMENT_VERTICAL_CENTER);
			contentPanel.setStyleName(Style.CONTENT_PANEL.getStyleName());
			contentPanel.setWidth(Size.CONTENT_WIDTH.getValue(),
					Size.CONTENT_WIDTH.getUnits());
			contentPanel.setHeight(Size.APP_HEIGHT.getValue(),
					Size.APP_HEIGHT.getUnits());
		}

		VerticalLayout contentBottomLayout = new VerticalLayout();
		contentBottomLayout.setStyleName(Style.CONTENT_BOTTOM.getStyleName());
		contentBottomLayout.setWidth(Size.HEADER_WIDTH.getValue(),
				Size.HEADER_WIDTH.getUnits());
		contentBottomLayout.setHeight(Size.CONTENT_BOTTOM_HEIGHT.getValue(),
				Size.CONTENT_BOTTOM_HEIGHT.getUnits());

		contentLayout.addComponent(contentTopLayout);
		contentLayout.addComponent(contentCenterLayout);
		contentLayout.setExpandRatio(contentCenterLayout, 1.0f);
		contentLayout.addComponent(contentBottomLayout);
		contentLayout.setSizeFull();

		vLayout.addComponent(header);
		vLayout.addComponent(contentLayout);
		vLayout.setExpandRatio(contentLayout, 1.0f);

		addComponent(vLayout);
		setComponentAlignment(vLayout, Alignment.TOP_CENTER);
	}

	/**
	 * @return the header
	 */
	public Header getHeader() {
		return header;
	}

}
